package com.xiaoy.core.report.fusionchart.radarChart.util;

import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.xiaoy.core.report.fusionchart.eg.model.Doughnut;



public class XMLDataGenerator {

//	static String currentMonth = new SimpleDateFormat("yyyy-MM-dd").format(new Date()).substring(0,7);
	

	public static String getCRRankXML(List<Doughnut> osList, String yearMonth) {
		String result = null;
		Document docement = DocumentHelper.createDocument();
		Element rootElement = docement.addElement("chart");
		rootElement = initPreference(rootElement);
		rootElement.addAttribute("exportHandler", "fcExporter1");
		rootElement.addAttribute("exportFileName", "CR 占比饼图");
		rootElement.addAttribute("caption", "CR 占比饼图");

		Element nameElement = null;
		for (Iterator<Doughnut> iterator = osList.iterator(); iterator.hasNext();) {
			Doughnut os = iterator.next();
			nameElement = rootElement.addElement("/");
			nameElement.addAttribute("label", os.getLabel());
			nameElement.addAttribute("value", os.getValue()+"");
		}
		result = docement.asXML().replace("\n", "").replace("\"", "\'");
		return result;
	}
	
	private static Element initPreference(Element rootElement) {
		rootElement.addAttribute("palette", "4");
		rootElement.addAttribute("decimals", "2");
		rootElement.addAttribute("exportEnabled", "1");
		rootElement.addAttribute("exportAtClient", "1");
		rootElement.addAttribute("showPercentageValues", "1");
		rootElement.addAttribute("enableSmartLabels", "1");
		rootElement.addAttribute("enableRotation", "0");
		rootElement.addAttribute("bgColor", "99CCFF,FFFFFF");
		rootElement.addAttribute("bgAlpha", "40,100");
		rootElement.addAttribute("bgRatio", "0,100");
		rootElement.addAttribute("bgAngle", "360");
		rootElement.addAttribute("showBorder", "1");
		rootElement.addAttribute("startingAngle", "70");
		rootElement.addAttribute("baseFontSize", "12");
		rootElement.addAttribute("bgRatio", "0,100");
		rootElement.addAttribute("exportDialogMessage", "正在转换...");
		rootElement.addAttribute("exportShowMenuItem", "0");
		return rootElement;
	}
}
